<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class ApplianceController extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
	}
	
	function addAppliance($student_number)
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$_POST['student_number']=$student_number;
		$this->load->model('Appliance_model');
		if($this->Appliance_model->check_appliance($_POST)){
			show_error('An Appliance with that control number already exists!');
		}else{
			$this->Appliance_model->add_appliance($_POST);
			redirect('residentController/loadSearchResidentView/'.$student_number);
		}}
	}
	
	function deleteAppliance()
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->model('Appliance_model');
		$this->Appliance_model->delete_appliance($_POST);
		redirect('residentController/loadSearchResidentView/'.$_POST['student_number']);}
	}
	
	function loadViewApplianceView($student_number,$control_number)
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$_POST['student_number']=$student_number;
		$_POST['control_number']=$control_number;
		$this->load->model('Appliance_model');
		$data['info'] = $this->Appliance_model->get_appliance($_POST);
		$data['title'] = 'View Appliance';
		$data['jsSnippet'] = 'jsSnippets/viewApplianceJsSnippet';
		$data['htmlSnippet'] = 'htmlSnippets/viewApplianceHtmlSnippet';
		$this->load->view('generic/GenericView',$data);}
	}
	
	function loadEditApplianceView($student_number,$control_number)
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$_POST['student_number']=$student_number;
		$_POST['control_number']=$control_number;
		$this->load->model('Appliance_model');
		$data['info'] = $this->Appliance_model->get_appliance($_POST);
		$data['title'] = 'Edit Appliance';
		$data['jsSnippet'] = 'jsSnippets/editApplianceJsSnippet';
		$data['htmlSnippet'] = 'htmlSnippets/editApplianceHtmlSnippet';
		$this->load->view('generic/GenericView',$data);}
	}
	
	function editAppliance()
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->model('Appliance_model');
		$this->Appliance_model->edit_appliance($_POST);
		redirect('residentController/loadSearchResidentView/'.$_POST['student_number']);}
	}
	
}

/* End of file applianceController.php */
/* Location: ./application/controllers/applianceController.php */
?>